﻿using ConfigHelper.Common;
using DataAccessLayer.BaseInterface;
using IDataAccessLayer;
using Model;
using Model.Extend_Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAccessLayer
{
    public class AdminTableDataAccessLayer : BaseDataAccessLayer<AdminTable>, IAdminTableDataAccessLayer
    {
        public override string TableName
        {
            get { return "AdminTable"; }
        }

        public override Dictionary<string, bool> PKname
        {
            get
            {
                Dictionary<string, bool> dic = new Dictionary<string, bool>();
                dic.Add("AdminId", true);
                return dic;
            }
        }

        public List<Admin_Extend> GetAdminList(params SqlParameter[] param)
        {
            //调用common 中拼好的Sql语句
            string Sql = Common.GetAdminList<Admin_Extend>(param);

            //调用DBHelper 返回DataTable类型
            DataTable dt = DBhelper.GetDataSet(Sql);

            List<Admin_Extend> admin = new List<Admin_Extend>();
            foreach (DataRow item in dt.Rows)
            {
                Type t1 = typeof(Admin_Extend);
                Admin_Extend t2 = (Admin_Extend)t1.Assembly.CreateInstance(t1.FullName);
                foreach (var i in t1.GetProperties())
                {
                    i.SetValue(t2, item[i.Name]);
                }
                admin.Add(t2);
            }
            return admin;
        }
    }
}
